! function (r, t) {
    (r = r || self).smCrypt = t()
}(this, function () {
   "use strict";

   function n(r, t) {
       if (!(r instanceof t)) throw new TypeError("Cannot call a class as a function")
   }

   function i(r, t) {
       for (var e = 0; e < t.length; e++) {
           var n = t[e];
           n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(r, n.key, n)
       }
   }

   function t(r, t, e) {
       return t && i(r.prototype, t), e && i(r, e), r
   }
   for (var u = [], s = [], y = "undefined" != typeof Uint8Array ? Uint8Array : Array, r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", e = 0, o = r.length; e < o; ++e) u[e] = r[e], s[r.charCodeAt(e)] = e;

   function h(r) {
       var t = r.length;
       if (0 < t % 4) throw new Error("Invalid string. Length must be a multiple of 4");
       r = r.indexOf("=");
       return [r = -1 === r ? t : r, r === t ? 0 : 4 - r % 4]
   }

   function f(r, t, e) {
       for (var n, i = [], o = t; o < e; o += 3) n = (r[o] << 16 & 16711680) + (r[o + 1] << 8 & 65280) + (255 & r[o + 2]), i.push(u[(n = n) >> 18 & 63] + u[n >> 12 & 63] + u[n >> 6 & 63] + u[63 & n]);
       return i.join("")
   }
   s["-".charCodeAt(0)] = 62, s["_".charCodeAt(0)] = 63;
   var a = {
           byteLength: function (r) {
               var r = (t = h(r))[0],
                   t = t[1];
               return 3 * (r + t) / 4 - t
           },
           toByteArray: function (r) {
               for (var t, e, n = (e = h(r))[0], i = e[1], o = new y(3 * (n + (e = i)) / 4 - e), a = 0, u = 0 < i ? n - 4 : n, f = 0; f < u; f += 4) t = s[r.charCodeAt(f)] << 18 | s[r.charCodeAt(f + 1)] << 12 | s[r.charCodeAt(f + 2)] << 6 | s[r.charCodeAt(f + 3)], o[a++] = t >> 16 & 255, o[a++] = t >> 8 & 255, o[a++] = 255 & t;
               return 2 === i && (t = s[r.charCodeAt(f)] << 2 | s[r.charCodeAt(f + 1)] >> 4, o[a++] = 255 & t), 1 === i && (t = s[r.charCodeAt(f)] << 10 | s[r.charCodeAt(f + 1)] << 4 | s[r.charCodeAt(f + 2)] >> 2, o[a++] = t >> 8 & 255, o[a++] = 255 & t), o
           },
           fromByteArray: function (r) {
               for (var t, e = r.length, n = e % 3, i = [], o = 0, a = e - n; o < a; o += 16383) i.push(f(r, o, a < o + 16383 ? a : o + 16383));
               return 1 == n ? (t = r[e - 1], i.push(u[t >> 2] + u[t << 4 & 63] + "==")) : 2 == n && (t = (r[e - 2] << 8) + r[e - 1], i.push(u[t >> 10] + u[t >> 4 & 63] + u[t << 2 & 63] + "=")), i.join("")
           }
       },
       p = function () {
           function r() {
               n(this, r)
           }
           return t(r, null, [{
               key: "stringToArrayBufferInUtf8",
               value: function (r) {
                   return (new("undefined" == typeof window ? require("util") : window).TextEncoder).encode(r)
               }
           }, {
               key: "utf8ArrayBufferToString",
               value: function (r) {
                   return new("undefined" == typeof window ? require("util") : window).TextDecoder("utf-8").decode(r)
               }
           }, {
               key: "arrayBufferToBase64",
               value: function (r) {
                   return a.fromByteArray(r)
               }
           }, {
               key: "base64ToArrayBuffer",
               value: function (r) {
                   return a.toByteArray(r)
               }
           }]), r
       }(),
       k = 16,
       c = Uint8Array.from([214, 144, 233, 254, 204, 225, 61, 183, 22, 182, 20, 194, 40, 251, 44, 5, 43, 103, 154, 118, 42, 190, 4, 195, 170, 68, 19, 38, 73, 134, 6, 153, 156, 66, 80, 244, 145, 239, 152, 122, 51, 84, 11, 67, 237, 207, 172, 98, 228, 179, 28, 169, 201, 8, 232, 149, 128, 223, 148, 250, 117, 143, 63, 166, 71, 7, 167, 252, 243, 115, 23, 186, 131, 89, 60, 25, 230, 133, 79, 168, 104, 107, 129, 178, 113, 100, 218, 139, 248, 235, 15, 75, 112, 86, 157, 53, 30, 36, 14, 94, 99, 88, 209, 162, 37, 34, 124, 59, 1, 33, 120, 135, 212, 0, 70, 87, 159, 211, 39, 82, 76, 54, 2, 231, 160, 196, 200, 158, 234, 191, 138, 210, 64, 199, 56, 181, 163, 247, 242, 206, 249, 97, 21, 161, 224, 174, 93, 164, 155, 52, 26, 85, 173, 147, 50, 48, 245, 140, 177, 227, 29, 246, 226, 46, 130, 102, 202, 96, 192, 41, 35, 171, 13, 83, 78, 111, 213, 219, 55, 69, 222, 253, 142, 47, 3, 255, 106, 114, 109, 108, 91, 81, 141, 27, 175, 146, 187, 221, 188, 127, 17, 217, 92, 65, 31, 16, 90, 216, 10, 193, 49, 136, 165, 205, 123, 189, 45, 116, 208, 18, 184, 229, 180, 176, 137, 105, 151, 74, 12, 150, 119, 126, 101, 185, 241, 9, 197, 110, 198, 132, 24, 240, 125, 236, 58, 220, 77, 32, 121, 238, 95, 62, 215, 203, 57, 72]),
       l = Uint32Array.from([462357, 472066609, 943670861, 1415275113, 1886879365, 2358483617, 2830087869, 3301692121, 3773296373, 4228057617, 404694573, 876298825, 1347903077, 1819507329, 2291111581, 2762715833, 3234320085, 3705924337, 4177462797, 337322537, 808926789, 1280531041, 1752135293, 2223739545, 2695343797, 3166948049, 3638552301, 4110090761, 269950501, 741554753, 1213159005, 1684763257]),
       d = Uint32Array.from([2746333894, 1453994832, 1736282519, 2993693404]);
   return function () {
       function e(r) {
           n(this, e);
           var t = p.stringToArrayBufferInUtf8(r.key);
           if (16 !== t.length) throw new Error("key should be a 16 bytes string");
           this.key = t;
           t = new Uint8Array(0);
           if (void 0 !== r.iv && null !== r.iv && 16 !== (t = p.stringToArrayBufferInUtf8(r.iv)).length) throw new Error("iv should be a 16 bytes string");
           this.iv = t, 0 <= [this.mode = "cbc", "ecb"].indexOf(r.mode) && (this.mode = r.mode), 0 <= [this.cipherType = "base64", "text"].indexOf(r.outType) && (this.cipherType = r.outType), this.encryptRoundKeys = new Uint32Array(32), this.spawnEncryptRoundKeys(), this.decryptRoundKeys = Uint32Array.from(this.encryptRoundKeys), this.decryptRoundKeys.reverse()
       }
       return t(e, [{
           key: "doBlockCrypt",
           value: function (r, t) {
               var e = new Uint32Array(36);
               e.set(r, 0);
               for (var n = 0; n < 32; n++) e[n + 4] = e[n] ^ this.tTransform1(e[n + 1] ^ e[n + 2] ^ e[n + 3] ^ t[n]);
               r = new Uint32Array(4);
               return r[0] = e[35], r[1] = e[34], r[2] = e[33], r[3] = e[32], r
           }
       }, {
           key: "spawnEncryptRoundKeys",
           value: function () {
               var r = new Uint32Array(4);
               r[0] = this.key[0] << 24 | this.key[1] << 16 | this.key[2] << 8 | this.key[3], r[1] = this.key[4] << 24 | this.key[5] << 16 | this.key[6] << 8 | this.key[7], r[2] = this.key[8] << 24 | this.key[9] << 16 | this.key[10] << 8 | this.key[11], r[3] = this.key[12] << 24 | this.key[13] << 16 | this.key[14] << 8 | this.key[15];
               var t = new Uint32Array(36);
               t[0] = r[0] ^ d[0], t[1] = r[1] ^ d[1], t[2] = r[2] ^ d[2], t[3] = r[3] ^ d[3];
               for (var e = 0; e < 32; e++) t[e + 4] = t[e] ^ this.tTransform2(t[e + 1] ^ t[e + 2] ^ t[e + 3] ^ l[e]), this.encryptRoundKeys[e] = t[e + 4]
           }
       }, {
           key: "rotateLeft",
           value: function (r, t) {
               return r << t | r >>> 32 - t
           }
       }, {
           key: "linearTransform1",
           value: function (r) {
               return r ^ this.rotateLeft(r, 2) ^ this.rotateLeft(r, 10) ^ this.rotateLeft(r, 18) ^ this.rotateLeft(r, 24)
           }
       }, {
           key: "linearTransform2",
           value: function (r) {
               return r ^ this.rotateLeft(r, 13) ^ this.rotateLeft(r, 23)
           }
       }, {
           key: "tauTransform",
           value: function (r) {
               return c[r >>> 24 & 255] << 24 | c[r >>> 16 & 255] << 16 | c[r >>> 8 & 255] << 8 | c[255 & r]
           }
       }, {
           key: "tTransform1",
           value: function (r) {
               r = this.tauTransform(r);
               return this.linearTransform1(r)
           }
       }, {
           key: "tTransform2",
           value: function (r) {
               r = this.tauTransform(r);
               return this.linearTransform2(r)
           }
       }, {
           key: "padding",
           value: function (r) {
               if (null === r) return null;
               var t = k - r.length % k,
                   e = new Uint8Array(r.length + t);
               return e.set(r, 0), e.fill(t, r.length), e
           }
       }, {
           key: "dePadding",
           value: function (r) {
               if (null === r) return null;
               var t = r[r.length - 1];
               return r.slice(0, r.length - t)
           }
       }, {
           key: "uint8ToUint32Block",
           value: function (r) {
               var t = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : 0,
                   e = new Uint32Array(4);
               return e[0] = r[t] << 24 | r[t + 1] << 16 | r[t + 2] << 8 | r[t + 3], e[1] = r[t + 4] << 24 | r[t + 5] << 16 | r[t + 6] << 8 | r[t + 7], e[2] = r[t + 8] << 24 | r[t + 9] << 16 | r[t + 10] << 8 | r[t + 11], e[3] = r[t + 12] << 24 | r[t + 13] << 16 | r[t + 14] << 8 | r[t + 15], e
           }
       }, {
           key: "encrypt",
           value: function (r) {
               var r = p.stringToArrayBufferInUtf8(r),
                   t = this.padding(r),
                   e = t.length / k,
                   n = new Uint8Array(t.length);
               if ("cbc" === this.mode) {
                   if (null === this.iv || 16 !== this.iv.length) throw new Error("iv error");
                   for (var i = this.uint8ToUint32Block(this.iv), o = 0; o < e; o++) {
                       var a = o * k,
                           u = this.uint8ToUint32Block(t, a);
                       i[0] = i[0] ^ u[0], i[1] = i[1] ^ u[1], i[2] = i[2] ^ u[2], i[3] = i[3] ^ u[3];
                       for (var f = this.doBlockCrypt(i, this.encryptRoundKeys), i = f, s = 0; s < k; s++) n[a + s] = f[parseInt(s / 4)] >> (3 - s) % 4 * 8 & 255
                   }
               } else
                   for (var y = 0; y < e; y++)
                       for (var h = y * k, c = this.uint8ToUint32Block(t, h), l = this.doBlockCrypt(c, this.encryptRoundKeys), d = 0; d < k; d++) n[h + d] = l[parseInt(d / 4)] >> (3 - d) % 4 * 8 & 255;
               return "base64" === this.cipherType ? p.arrayBufferToBase64(n) : p.utf8ArrayBufferToString(n)
           }
       }, {
           key: "decrypt",
           value: function (r) {
               var t = new Uint8Array,
                   e = (t = "base64" === this.cipherType ? p.base64ToArrayBuffer(r) : p.stringToArrayBufferInUtf8(r)).length / k,
                   n = new Uint8Array(t.length);
               if ("cbc" === this.mode) {
                   if (null === this.iv || 16 !== this.iv.length) throw new Error("iv error");
                   for (var i = this.uint8ToUint32Block(this.iv), o = 0; o < e; o++) {
                       var a = o * k,
                           u = this.uint8ToUint32Block(t, a),
                           f = this.doBlockCrypt(u, this.decryptRoundKeys),
                           s = new Uint32Array(4);
                       s[0] = i[0] ^ f[0], s[1] = i[1] ^ f[1], s[2] = i[2] ^ f[2], s[3] = i[3] ^ f[3];
                       for (var i = u, y = 0; y < k; y++) n[a + y] = s[parseInt(y / 4)] >> (3 - y) % 4 * 8 & 255
                   }
               } else
                   for (var h = 0; h < e; h++)
                       for (var c = h * k, l = this.uint8ToUint32Block(t, c), d = this.doBlockCrypt(l, this.decryptRoundKeys), v = 0; v < k; v++) n[c + v] = d[parseInt(v / 4)] >> (3 - v) % 4 * 8 & 255;
               r = this.dePadding(n);
               return p.utf8ArrayBufferToString(r)
           }
       }]), e
   }()
});